<%@ page language="java" import="java.util.*,entity.*,dao.*,dao.impl.*" pageEncoding="utf-8"%>
<%String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<%
	TopicDao topicDao = new TopicDaoImpl();
	ReplyDao replyDao = new ReplyDaoImpl();
	UserDao userDao =new UserDaoImpl();
	BoardDao boardDao = new BoardDaoImpl();
	int p =Integer.parseInt(request.getParameter("page"));
	int boardId = Integer.parseInt(request.getParameter("boardId"));
	List listTopic = topicDao.findListTopic(p, boardId);
	Board board =boardDao.findBoard(boardId);
	
	int prep =p;
	int nextp = p;
	if(listTopic.size() == 20){
		nextp =p +1;
	}
	if(p>1){
	prep = p-1;
	}
 %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    <title>帖子列表</title>
        <style>
            *{margin:0;padding:0;}
            .divhead{
            margin-top:50px;
            height:50px; 
            text-align: center;
            line-height:50px; 
            }
            .divhead>p{
            text-shadow:#FF0000 0 0 10px;
            color:black;
            font-size:60px
            }
            .div2{
                margin-top:30px;
                text-align:center;
               
            }
            .div2>p{
                background-color: gray;
            }
            .div3{
	            width:800px;
                color:black;
                text-align: left;
                margin-left: 70px;
	        }
            .div4{
                color: black;
                align-self: center;
                margin-bottom: 100px;
            }
            .div5{
                background-color: plum;
            }
            table{
                border:2px solid burlywood;
                width:1000px;
                height:700px;
                margin:auto;
            }
            a:link{
                color:salmon;
            }
            a:visited{
                color:bisque;
            }
            a:hover{
                color:red;
            }
            .button{
                font-size: 16px;
                border-radius: 6px;
                width:10%;
                box-shadow: 10px;
            }
        </style>
    </head>
    <body background="img/background.jpg">
        <div class="divhead">
            <p>北京科技大学天津学院BBS</p>
        </div>
        <div class ="div2">
            <%if(session.getAttribute("user")==null){ %>
            <p>您尚未<a href="login.jsp" target ="_blank">登录</a> | <a href="reg.jsp" target ="_blank">注册</a> 
            <%}else{            
            	User loginUser =(User)session.getAttribute("user"); 
            %>
            	您好：<%= loginUser.getUName() %></p>
             <%} %>
        </div>
        
        <div class="div3">&gt;&gt;&gt;<a href="index.jsp">论坛首页</a>&gt;&gt;
        <%String boardName=board.getBoardName();%>
        <%=boardName%>
        <p><a href="post.jsp?boardId=<%=boardId%>&boardName=<%=boardName%>">发表帖子</a></p>
        </div>
        
        <div class="div4">
            
              <table width="800" border="1" cellspacing="0" cellpadding="0">
                <tr>
                  <td colspan="4" >&nbsp;</td>
                </tr>
                <tr>
                  <td width="41">&nbsp;</td>
                  <td width="381">文章</td>
                  <td width="181">作者</td>
                  <td width="191">回复</td>
                </tr>
                <!-- 主题列表 -->
                <%
                	for(int i=0;i<listTopic.size();i++){
                	Topic topic = (Topic)listTopic.get(i);
                	User user =userDao.findUser(topic.getUid());	
                 %>
                <tr>
                  <td>&nbsp;</td>
                  <td><a href="detail.jsp?page=1&boardId=<%=boardId%>&topicId=<%=topic.getTopicId() %>">
                  <%= topic.getTitle() %></a></td>
                  <td><%= user.getUName() %></td>
                  <td><%= replyDao.findCountReply(topic.getTopicId()) %></td>
                </tr>
				<%
				 }
				 %>
                <tr>
                    <td colspan="4" align="center">
                    	<a href="list.jsp?page=<%=prep%>&boardId=<%=boardId%>">上一页</a>|
                    	<a href="list.jsp?page=<%=nextp%>&boardId=<%=boardId%>">下一页</a>
                    	当前第<%=p%>页
                
                    	</td>
                </tr>
              </table>
          </div>
    </body>
    
</html>
